import 'package:flutter/material.dart';
import '../model/post.dart';
import './pageView_demo.dart';
class ViewDemo extends StatelessWidget{
  

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return GridVeiwBuilder();
  }
}

class GridVeiwBuilder extends StatelessWidget {
  Widget _builder(BuildContext context ,int index) {
    return Stack(
      children: <Widget>[
        SizedBox.expand(
          child: Image.network(posts[index].imageUrl,fit: BoxFit.cover,)
        )
      ],
    );
  }
  @override
  Widget build(BuildContext context) {
    return GridView.builder(
      itemCount: posts.length,
      gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 3,
        crossAxisSpacing: 15,
        mainAxisSpacing: 15,
      ),
      itemBuilder: _builder,
    );
  }
}

class GridViewExtend extends StatelessWidget {
  List<Widget> _builderItems(int count){
    return List.generate(count, (int index){
      return Container(
        alignment: Alignment(0, 0),
        decoration: BoxDecoration(
         color: Colors.grey[100],
         borderRadius: BorderRadius.all(Radius.circular(5.0))
       ),
       child: Text(
         'Item$index',
         style: TextStyle(color: Colors.white,fontSize: 20,fontWeight: FontWeight.bold),
       )
      );
    });
  }
  @override
  Widget build(BuildContext context) {
    return GridView.extent(
      maxCrossAxisExtent: 900,
      crossAxisSpacing: 15,
      mainAxisSpacing: 14,
      children: _builderItems(100),
    );
  }
}

class GridViewCountDemo extends StatelessWidget {
  List<Widget> _builderItems(int count){
    return List.generate(count, (int index ){
      return Container(
          color: Colors.green[200],
          alignment: Alignment(0,0),
          child: Text(
            'Item $index',
            style: TextStyle(fontSize: 18,fontWeight: FontWeight.bold,color: Colors.grey),
          ),
        );
    });
  }
  @override
  Widget build(BuildContext context) {
    return GridView.count(
      crossAxisCount: 3,
      crossAxisSpacing: 16,
      mainAxisSpacing: 15,
      scrollDirection: Axis.vertical,
      children:_builderItems(200)
    );
  }
}

class PageViewBuilder extends StatelessWidget{
  Widget _pageBuilder(BuildContext context, int index) {
     return Stack(
       children: <Widget>[
         SizedBox.expand(
           child: Image.network(posts[index].imageUrl,fit: BoxFit.cover,),
         ),
         Positioned(
           bottom: 9.0,
           left: 9.0,
           child: Column(
             crossAxisAlignment: CrossAxisAlignment.start,
             children: <Widget>[
               Text(
                 posts[index].title,
                 style: TextStyle(fontSize: 25,fontWeight: FontWeight.bold,color: Colors.black),
               ),
               Text(
                 posts[index].title,
                 style: TextStyle(fontSize: 15,fontWeight: FontWeight.normal,color: Colors.grey),
               ),
             ],
           ),
         )
       ],
     );
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return PageView.builder(
      itemCount: posts.length,
      itemBuilder: _pageBuilder,
    );
  }
}